public class Solution {
     public int[] list2array(ArrayList<Integer> pre1){
        int pre1_[]=new int[pre1.size()];
        for(int i=0;i<pre1.size();i++)
        {
            pre1_[i]=((Integer)pre1.get(i)).intValue();
        }
        return pre1_;
    }

    public TreeNode reConstructBinaryTree(int [] pre,int [] in) {
        TreeNode root = null;
        ArrayList<Integer> pre1 = new ArrayList<>();
        ArrayList<Integer> pre2 = new ArrayList<>();
        ArrayList<Integer> in1 = new ArrayList<>();
        ArrayList<Integer> in2 = new ArrayList<>();
        boolean signal = true;
        int inIndex = -1;
        if(pre.length!=0){
            root = new TreeNode(pre[0]);
            for(int i=0; i<in.length; i++){
                if(in[i] == pre[0]){
                    signal = false;
                    continue;
                }
                if(signal){
                    in1.add(in[i]);
                }else{
                    in2.add(in[i]);
                }
            }
            for(int i=0; i<in1.size(); i++){
                pre1.add(pre[i+1]);
            }
            for (int i=0; i<in2.size(); i++){
                pre2.add(pre[i+in1.size()+1]);
            }
            root.left = reConstructBinaryTree(list2array(pre1), list2array(in1));
            root.right = reConstructBinaryTree(list2array(pre2), list2array(in2));
            return root;
        }else{
            return root;
        }
    }

}